package com.yaoli.ajob;

/**
 * Created by siemens on 4/5/2017.
 */
public class _338_CountingBits {
    public static void main(String[] args) {
        _338_CountingBits countingBits = new _338_CountingBits();
        countingBits.countBits(10);
    }

    /**
     *
     * @param num
     * @return
     *
     *
     * 归纳起来 就是当前 的 除以 2 然后加上 奇数 加1 偶数 加0
     *
     */
    public int[] countBits(int num) {
        int[] f = new int[num + 1];
        for (int i=1; i<=num; i++) {
            f[i] = f[i / 2] + i % 2;
        }
        return f;
    }
}
